const { query } = require('../../../lib/db');
const { authenticateToken } = require('../../../lib/auth');

async function handler(req, res) {
  if (req.method !== 'GET') {
    return res.status(405).json({
      success: false,
      message: '方法不允许'
    });
  }

  try {
    // 查询所有支持人员
    const supportStaff = await query(
      `SELECT 
        id, name, employee_id, department, email, phone
      FROM users 
      WHERE role IN ('support', 'administrator', 'operator') 
        AND status = 1 
      ORDER BY name`,
      []
    );

    res.status(200).json({
      success: true,
      data: supportStaff
    });

  } catch (error) {
    console.error('支持人员列表错误:', error);
    res.status(500).json({
      success: false,
      message: '服务器内部错误'
    });
  }
}

export default authenticateToken(handler);